<template>
  <div class="app-container">
    <!-- 案件登记 -->
    <!-- 查询和其他操作 -->
    <el-form :inline="true" class="demo-form-inline filter">
      <div>
        <el-form-item label="报修日期">
          <el-date-picker
            v-model="alarmdate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item label="报修单号">
          <el-input
            v-model="listQuery.fbillno"
            clearable
            class="filter-item"
            style="width: 200px"
            placeholder="请输入报修单号"
          />
        </el-form-item>
        <el-form-item label="报修状态">
          <el-select
            v-model="listQuery.fbillstate"
            class="filter-item"
            style="width: 200px"
            clearable
            placeholder="请选择报修状态"
          >
            <el-option
              v-for="item in fbillstateOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>
      <div>
        <span v-if="this.$store.state.user.fsiteLevel == 3">
          <el-form-item label="客户名称">
            <el-select
              v-model="listQuery.fsiteNo"
              disabled
              clearable
              filterable
              class="filter-item"
              placeholder="请选择客户名称"
            >
              <el-option
                v-for="item in getListfsiteNo"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="报修人员">
            <div
              style="
              width: 220px;
              display: flex;
              justify-content: flex-end;
              align-items: center;
            "
            >
              <el-select
                v-model="listQuery.freportuser"
                style="display: inline-block; width: 200px"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择报修人员"
              >
                <el-option
                  v-for="item in getListuser"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <i
                style="
                display: inline-block;
                width: 20px;
                color: #409eff;
                margin-left: 3px;
              "
                class="el-icon-search"
                @click="searchDialoguse('search')"
              />
            </div>
          </el-form-item>
          <el-form-item label="存放地点">
            <div
              style="
              width: 220px;
              display: flex;
              justify-content: flex-end;
              align-items: center;
            "
            >
              <el-select
                v-model="listQuery.fpointNo"
                style="display: inline-block; width: 200px"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择巡查地点"
              >
                <el-option
                  v-for="item in getListfpointNo"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <i
                style="
                display: inline-block;
                width: 20px;
                color: #409eff;
                margin-left: 3px;
              "
                class="el-icon-search"
                @click="searchDialoglab('search')"
              />
            </div>
          </el-form-item>
          <el-form-item label="维修人员">
            <div
              style="
              width: 220px;
              display: flex;
              justify-content: flex-end;
              align-items: center;
            "
            >
              <el-select
                v-model="listQuery.frepairuser"
                style="display: inline-block; width: 200px"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择维修人员"
              >
                <el-option
                  v-for="item in getListuser"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <i
                style="
                display: inline-block;
                width: 20px;
                color: #409eff;
                margin-left: 3px;
              "
                class="el-icon-search"
                @click="searchDialoguse('searchre')"
              />
            </div>
          </el-form-item>
        </span>
        <span v-else>
          <el-form-item label="客户名称">
            <el-select
              v-model="listQuery.fsiteNo"
              clearable
              filterable
              class="filter-item"
              placeholder="请选择客户名称"
              @change="changeFsiteNo"
            >
              <el-option
                v-for="item in getListfsiteNo"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="报修人员">
            <div
              style="
              width: 220px;
              display: flex;
              justify-content: flex-end;
              align-items: center;
            "
            >
              <el-select
                v-model="listQuery.freportuser"
                style="display: inline-block; width: 200px"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择报修人员"
              >
                <el-option
                  v-for="item in getListuserArea"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <i
                style="
                display: inline-block;
                width: 20px;
                color: #409eff;
                margin-left: 3px;
              "
                class="el-icon-search"
                @click="searchDialoguse('search')"
              />
            </div>
          </el-form-item>
          <el-form-item label="存放地点">
            <div
              style="
              width: 220px;
              display: flex;
              justify-content: flex-end;
              align-items: center;
            "
            >
              <el-select
                v-model="listQuery.fpointNo"
                style="display: inline-block; width: 200px"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择巡查地点"
              >
                <el-option
                  v-for="item in getListfpointNoArea"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <i
                style="
                display: inline-block;
                width: 20px;
                color: #409eff;
                margin-left: 3px;
              "
                class="el-icon-search"
                @click="searchDialoglab('search')"
              />
            </div>
          </el-form-item>
          <el-form-item label="维修人员">
            <div
              style="
              width: 220px;
              display: flex;
              justify-content: flex-end;
              align-items: center;
            "
            >
              <el-select
                v-model="listQuery.frepairuser"
                style="display: inline-block; width: 200px"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择维修人员"
              >
                <el-option
                  v-for="item in getListuserArea"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <i
                style="
                display: inline-block;
                width: 20px;
                color: #409eff;
                margin-left: 3px;
              "
                class="el-icon-search"
                @click="searchDialoguse('searchre')"
              />
            </div>
          </el-form-item>
        </span>
      </div>
      <el-form-item>
        <!-- v-permission="['fault:repairHead:read']" -->
        <el-button
          :style="{ background: buttonColor.lookup, color: buttonColor.color }"
          round
          size="medium"
          class="filter-item"
          @click="handleFilter"
        >查找</el-button
        >
        <!-- v-permission="['fault:repairHead:create']" -->
        <el-button
          :style="{ background: buttonColor.add, color: buttonColor.color }"
          round
          size="medium"
          class="filter-item"
          @click="handleCreate"
        >添加</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 查询结果 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      :header-cell-style="tableColor"
      stripe
      element-loading-text="正在查询中。。。"
      border
      fit
      highlight-current-row
    >
      <el-table-column :width="buttonColor.operationTwo" align="center" label="操作" class-name="small-padding" >
        <template slot-scope="scope">
          <!-- v-permission="['purchase:head:update']" -->
          <div class="operationButton">
            <div :style="{color:buttonColor.edit,cursor:'pointer'}" @click="handleUpdate(scope.row)">
              <img src="../../../public/images/edit.png" >
              编辑
            </div>

            <div :style="{color:buttonColor.edit,cursor:'pointer'}" @click="audit(scope.row)">
              <img src="../../../public/images/examine.png" >
              派工
            </div>

            <div :style="{color:buttonColor.edit,cursor:'pointer'}" @click="handleDelete(scope.row)">
              <img src="../../../public/images/del.png" >
              删除
            </div>

            <div :style="{color:buttonColor.edit,cursor:'pointer'}" >
              <img src="../../../public/images/print.png" >
              打印
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        :index="indexMethod"
        align="center"
        label="序"
        type="index"
      />
      <el-table-column
        align="center"
        label="报修单号"
        prop="fbillno"
        width="160"
      />
      <el-table-column
        v-if="this.$store.state.user.fsiteLevel != 3"
        :formatter="formatfsiteNo"
        width="200"
        align="center"
        label="客户名称"
        prop="fsiteNo"
      />
      <el-table-column
        :formatter="formatfpointNo"
        align="center"
        label="存放地点"
        prop="fpointNo"
      />
      <el-table-column
        :formatter="formatfreportuser"
        align="center"
        label="报修人员"
        prop="freportuser"
      />
      <el-table-column
        :formatter="datetimeFormat"
        width="100"
        align="center"
        label="报修日期"
        prop="freportdate"
      />
      <el-table-column
        width="150"
        align="center"
        label="固定资产码"
        prop="fequipmentbarcode"
      />
      <el-table-column align="center" label="设备名称" prop="fequipmenttag" />
      <el-table-column align="center" label="维护合约" prop="freporttype">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.freporttype">{{
            scope.row.freporttype | freporttypeFilter
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" label="故障描述" prop="ferrormemo" />
      <el-table-column
        :formatter="formatferrorlevel"
        align="center"
        label="紧急程度"
        prop="ferrorlevel"
      />
      <el-table-column
        :formatter="formatfrepairuser"
        align="center"
        label="维修人员"
        prop="frepairuser"
      />
      <el-table-column
        :formatter="datetimeFormat"
        width="100"
        align="center"
        label="接单日期"
        prop="frecdate"
      />
      <el-table-column align="center" label="报修状态" prop="fbillstate">
        <template slot-scope="scope">
          <span v-if="scope.row.fbillstate === 1" :style="{ color: buttonColor.itemisconfirmed }">{{
            scope.row.fbillstate |
              siteTypeFilter
          }}</span>
          <span v-else-if="scope.row.fbillstate === 2" :style="{ color: buttonColor.itemconfirmed }">{{
            scope.row.fbillstate | siteTypeFilter
          }}</span>
          <span v-else :style="{ color: buttonColor.iteminvalid }">{{ scope.row.fbillstate | siteTypeFilter }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
      width="auto"
    >
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="dataForm"
        status-icon
        label-position="left"
        label-width="auto"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="报修单号" prop="fbillno">
              <el-input :disabled="true" v-model="dataForm.fbillno" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报修日期" prop="freportdate">
              <el-date-picker
                v-model="dataForm.freportdate"
                disabled
                type="date"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报修状态" prop="fbillstate">
              <el-select
                :disabled="true"
                v-model="dataForm.fbillstate"
                class="filter-item"
                clearable
                placeholder="请选择报修状态"
              >
                <el-option
                  v-for="item in fbillstateOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item
              v-if="this.$store.state.user.fsiteLevel == 3"
              label="客户名称"
              prop="fsiteNo"
            >
              <el-select
                v-model="dataForm.fsiteNo"
                disabled
                clearable
                filterable
                class="filter-item"
                placeholder="请选择客户名称"
              >
                <el-option
                  v-for="item in getListfsiteNo"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item v-else label="客户名称" prop="fsiteNo">
              <el-select
                v-if="dialogStatus == 'create'"
                v-model="dataForm.fsiteNo"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择客户名称"
                @change="changeFsiteNoAdd"
              >
                <el-option
                  v-for="item in getListfsiteNo"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              <el-select
                v-else
                v-model="dataForm.fsiteNo"
                disabled
                clearable
                filterable
                class="filter-item"
                placeholder="请选择客户名称"
              >
                <el-option
                  v-for="item in getListfsiteNo"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-if="this.$store.state.user.fsiteLevel == 3"
              label="存放地点"
              prop="fpointNo"
            >
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm.fpointNo"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择存放地点"
                  @change="changeFpointNo"
                >
                  <el-option
                    v-for="item in getListfpointNo"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoglab('add')"
                />
              </div>
            </el-form-item>
            <el-form-item v-else label="存放地点" prop="fpointNo">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm.fpointNo"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择存放地点"
                  @change="changeFpointNo"
                >
                  <el-option
                    v-for="item in getListfpointNoAreaAdd"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoglab('add')"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-if="this.$store.state.user.fsiteLevel == 3"
              label="报修人员"
              prop="freportuser"
            >
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm.freportuser"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择报修人员"
                >
                  <el-option
                    v-for="item in getListuser"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoguse('add')"
                />
              </div>
            </el-form-item>
            <el-form-item v-else label="报修人员" prop="freportuser">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm.freportuser"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择报修人员"
                >
                  <el-option
                    v-for="item in getListuserAreaAdd"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoguse('add')"
                />
              </div>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="固定资产码" prop="fequipmentbarcode">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-input
                  v-model="dataForm.fequipmentbarcode"
                  style="display: inline-block"
                />
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialogcode"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备名称" prop="fequipmenttag">
              <el-input v-model="dataForm.fequipmenttag" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="维护合约" prop="freporttype">
              <el-select
                v-model="dataForm.freporttype"
                class="filter-item"
                clearable
                placeholder="请选择维护合约"
              >
                <el-option
                  v-for="item in freporttypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="紧急程度" prop="ferrorlevel">
              <el-select
                v-model="dataForm.ferrorlevel"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择紧急程度"
              >
                <el-option
                  v-for="item in getListferrorlevel"
                  :key="item.value"
                  :label="item.label"
                  :value="Number(item.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              v-if="this.$store.state.user.fsiteLevel == 3"
              label="维修人员"
              prop="frepairuser"
            >
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm.frepairuser"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择维修人员"
                  @change="frepairuserChange"
                >
                  <el-option
                    v-for="item in getListuser"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoguse('addre')"
                />
              </div>
            </el-form-item>
            <el-form-item v-else label="维修人员" prop="frepairuser">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm.frepairuser"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择维修人员"
                  @change="frepairuserChange"
                >
                  <el-option
                    v-for="item in getListuserAreaAdd"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoguse('addre')"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="接单日期" prop="frecdate">
              <el-date-picker v-model="dataForm.frecdate" type="date" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="故障描述" prop="ferrormemo">
              <el-input v-model="dataForm.ferrormemo" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-tabs type="border-card">
        <el-tab-pane label="设备照片">
          <div class="app-container">
            <!-- 子表查询和其他操作 -->
            <div class="filter-container">
              <el-button
                :style="{
                  background: buttonColor.add,
                  color: buttonColor.color,
                }"
                round
                size="medium"
                class="filter-item"
                @click="handleUpdate1"
              >添加</el-button
              >
            </div>

            <!-- 子表查询结果 -->
            <el-table
              v-loading="listLoading"
              :data="dataForm.details"
              :header-cell-style="tableColor"
              stripe
              element-loading-text="正在查询中。。。"
              border
              fit
              highlight-current-row
              height="15vh"
            >
              <el-table-column
                :index="indexMethod"
                align="center"
                label="序"
                type="index"
              />
              <el-table-column align="center" label="照片" prop="fimage">
                <template slot-scope="scope">
                  <img :src="scope.row.fimage" class="avatar" >
                </template>
              </el-table-column>
              <el-table-column align="center" label="备注" prop="fmemo" />
              <el-table-column
                align="center"
                label="操作"
                class-name="small-padding"
              >
                <template slot-scope="scope">
                  <el-button
                    :style="{
                      background: buttonColor.delete,
                      color: buttonColor.color,
                    }"
                    round
                    size="small"
                    class="button-margin"
                    @click="handleDelete1(scope.row)"
                  >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </div>
      </el-tab-pane></el-tabs
      >

      <div slot="footer" class="dialog-footer">
        <el-button
          :style="{
            background: buttonColor.cancel,
            color: buttonColor.colorone,
          }"
          @click="cancel()"
        >取消</el-button
        >
        <el-button
          v-if="dialogStatus == 'create'"
          :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="createData"
        >确定</el-button
        >
        <el-button
          v-else
          :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="updateData"
        >确定</el-button
        >
      </div>
    </el-dialog>

    <!-- 子表添加或修改对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible1"
      width="auto"
    >
      <template slot="title">
        <div :style="titleColor">{{ textMap[dialogStatus] }}</div>
      </template>
      <el-form
        ref="dataForm1"
        :rules="rules1"
        :model="dataForm"
        status-icon
        label-position="left"
        label-width="auto"
        style="width: 400px; margin: 0 30px"
      >
        <el-form-item label="照片" prop="fimage">
          <el-upload
            v-model="dataForm.fimage"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
            :action="uploadPath"
            :data="formdata2(dataForm.fbillno)"
            class="avatar-uploader"
          >
            <img v-if="heddon" :src="dataForm.fimage" class="avatar" >
            <i
              v-else
              class="el-icon-plus avatar-uploader-icon"
              style="font-size: 9px"
            />
          </el-upload>
        </el-form-item>
        <el-form-item label="备注" prop="fmemo">
          <el-input v-model="dataForm.fmemo" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible1 = false">取消</el-button>
        <el-button
          :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="addData"
        >确定</el-button
        >
      </div>
    </el-dialog>

    <!--派共-->
    <el-dialog :visible.sync="dialogVisible" title="提示" width="auto">
      <el-form
        ref="dataForm2"
        :rules="rules2"
        :model="dataForm2"
        status-icon
        label-position="left"
        label-width="auto"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="报修单号" prop="fbillno">
              <el-input :disabled="true" v-model="dataForm2.fbillno" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报修日期" prop="freportdate">
              <el-date-picker
                v-model="dataForm2.freportdate"
                disabled
                type="date"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报修状态" prop="fbillstate">
              <el-select
                :disabled="true"
                v-model="dataForm2.fbillstate"
                class="filter-item"
                clearable
                placeholder="请选择报修状态"
              >
                <el-option
                  v-for="item in fbillstateOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="客户名称" prop="fsiteNo">
              <el-select
                v-model="dataForm2.fsiteNo"
                disabled
                clearable
                filterable
                class="filter-item"
                placeholder="请选择客户名称"
              >
                <el-option
                  v-for="item in getListfsiteNo"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="存放地点" prop="fpointNo">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm2.fpointNo"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择存放地点"
                  disabled
                  @change="changeFpointNo"
                >
                  <el-option
                    v-for="item in getListfpointNoAreaAdd"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                    disabled
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoglab('add')"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报修人员" prop="freportuser">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm2.freportuser"
                  style="display: inline-block"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择报修人员"
                  disabled
                >
                  <el-option
                    v-for="item in getListuserAreaAdd"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoguse('add')"
                />
              </div>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="固定资产码" prop="fequipmentbarcode">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-input
                  v-model="dataForm2.fequipmentbarcode"
                  disabled
                  style="display: inline-block"
                />
                <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialogcode"
                />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备名称" prop="fequipmenttag">
              <el-input v-model="dataForm2.fequipmenttag" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="维护合约" prop="freporttype">
              <el-select
                v-model="dataForm2.freporttype"
                class="filter-item"
                clearable
                placeholder="请选择维护合约"
                disabled
              >
                <el-option
                  v-for="item in freporttypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  disabled
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="紧急程度" prop="ferrorlevel">
              <el-select
                v-model="dataForm2.ferrorlevel"
                clearable
                filterable
                class="filter-item"
                placeholder="请选择紧急程度"
                disabled
              >
                <el-option
                  v-for="item in getListferrorlevel"
                  :key="item.value"
                  :label="item.label"
                  :value="Number(item.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="维修人员" prop="frepairuser">
              <div
                style="
                  display: flex;
                  justify-content: flex-end;
                  align-items: center;
                "
              >
                <el-select
                  v-model="dataForm2.frepairuser"
                  clearable
                  filterable
                  class="filter-item"
                  placeholder="请选择维修人员"
                >
                  <el-option
                    v-for="item in username"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
                <!-- <i
                  style="
                    display: inline-block;
                    color: #409eff;
                    margin-left: 3px;
                  "
                  class="el-icon-search"
                  @click="searchDialoguse('addre')"
                /> -->
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="接单日期" prop="frecdate">
              <el-date-picker v-model="dataForm2.frecdate" type="date" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item label="备注" prop="fmemo">
              <el-input v-model="dataForm2.fmemo" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button
          :style="{ background: buttonColor.confirm, color: buttonColor.color }"
          @click="adds()"
        >确定</el-button
        >
      </div>
    </el-dialog>

    <codeDialog
      :search-visiblecode.sync="searchVisiblecode"
      :fpoint-no.sync="codeDialogfpointNo"
      :fsite-no.sync="codeDialogFsiteNo"
      :table-color="tableColor"
      @codeDialog="codeDialogValue"
    />
    <userDialog
      :search-visibleuse.sync="searchVisibleuse"
      :fsite-no.sync="userDialogFsiteNo"
      :table-color="tableColor"
      @userDialog="userDialogValue"
    />
    <labDialog
      :search-visiblelab.sync="searchVisiblelab"
      :fsite-no.sync="labDialogFsiteNo"
      :table-color="tableColor"
      @labDialog="labDialogValue"
    />
  </div>
</template>

<style>
.button-margin {
  margin: 2px 0px;
}
.el-button + .el-button {
  margin-left: 1px;
}
.avatar {
  width: 60px;
  height: 60px;
  display: block;
}
</style>

<script>
import {
  listrepairHead,
  createrepairHead,
  updaterepairHead,
  deleterepairHead,
  userlist,
  createDispatch
} from '@/api/repairHead'
import Pagination from '@/components/Pagination'
import moment from 'moment'
import { tableColor, titleColor, buttonColor } from '@/filters/index'
import { uploadPath, listRoom } from '@/api/room'
import {
  getListArea,
  fsiteOptionsByLevel,
  getFbillno,
  listArea
} from '@/api/area'
import UserDialog from '@/components/UserDialog'
import LabDialog from '@/components/LabDialog'
import CodeDialog from '@/components/CodeDialog'

const siteTypeMap = {
  1: '已报修',
  2: '已接单'
}
const freporttypeMap = {
  1: '合约内',
  2: '合约外'
}
export default {
  name: 'STcRepairHead',
  components: { Pagination, UserDialog, LabDialog, CodeDialog },
  filters: {
    siteTypeFilter(type) {
      return siteTypeMap[type]
    },
    freporttypeFilter(type) {
      return freporttypeMap[type]
    }
  },
  data() {
    return {
      buttonColor: buttonColor,
      heddon: false,
      isActive: true,
      username: null,
      uploadPath,
      dialogVisible: false,
      getListfpointNoAreaAdd: null,
      getListfpointNoArea: null,
      getListuserAreaAdd: null,
      getListuserArea: null,

      labFlag: null,
      searchVisiblelab: false,
      labDialogFsiteNo: null,

      searchVisibleuse: false,
      userDialogFsiteNo: null,
      userFlag: null,

      searchVisiblecode: false,
      codeDialogFsiteNo: null,
      codeDialogfpointNo: null,

      getListuser: null,
      getListfpointNo: null,
      getListferrorlevel: null,
      getListfsiteNo: null,
      searchListAll: null,
      list: null,
      total: 0,
      listLoading: true,
      alarmdate: null,
      listQuery: {
        page: 1,
        limit: 20,
        fsiteNo: undefined,
        freportuser: undefined,
        freportdate: undefined,
        ftakedateStart: undefined,
        ftakedateEnd: undefined,
        fpointNo: undefined,
        fequipmentbarcode: undefined,
        feuipmentid: undefined,
        freporttype: undefined,
        ferrormemo: undefined,
        ferrorlevel: undefined,
        frepairuser: undefined,
        frecdate: undefined,
        fcfdate: undefined,
        fdddate: undefined,
        fwcdate: undefined,
        flkdate: undefined,
        fbjnum: undefined,
        fbjnote: undefined,
        fupddate: undefined,
        foperator: undefined,
        fcheckdate: undefined,
        fcheckuser: undefined,
        fbillstate: undefined,
        sort: 'create_time',
        order: 'desc'
      },
      dataForm: {
        fsiteNo: undefined,
        freportuser: undefined,
        freportdate: undefined,
        fpointNo: undefined,
        fequipmentbarcode: undefined,
        fequipmenttag: undefined,
        feuipmentid: undefined,
        freporttype: undefined,
        ferrormemo: undefined,
        ferrorlevel: undefined,
        frepairuser: undefined,
        frecdate: undefined,
        fcfdate: undefined,
        fdddate: undefined,
        fwcdate: undefined,
        flkdate: undefined,
        fbjnum: undefined,
        fbjnote: undefined,
        fupddate: undefined,
        foperator: undefined,
        fimage: undefined,
        fcheckdate: undefined,
        fcheckuser: undefined,
        fbillstate: undefined,
        userid: undefined,
        id: undefined,
        details: []
      },
      actionsTmp: [],
      listTmp: [],
      dialogFormVisible1: false,
      dialogStatus1: '',
      dataForm1: {},
      dataForm2: {
        userid: undefined
      },

      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      tableColor: tableColor,
      titleColor: titleColor,
      rules: {
        fsiteNo: [{ required: true, message: '客户编号不能为空' }],
        freportuser: [
          { required: true, message: '报修人员不能为空', trigger: 'blur' }
        ],
        freportdate: [{ required: true, message: '报修日期不能为空' }],
        fpointNo: [
          { required: true, message: '存放地点不能为空', trigger: 'blur' }
        ],
        fequipmentbarcode: [
          { required: true, message: '固定资产码不能为空', trigger: 'blur' }
        ],
        fequipmenttag: [
          { required: true, message: '设备名称不能为空', trigger: 'blur' }
        ],
        freporttype: [
          {
            type: 'number',
            message: '维护合约必须为数字值',
            transform: (value) => Number(value)
          }
        ],
        ferrormemo: [{ required: true, message: '故障描述不能为空' }],
        ferrorlevel: [
          {
            type: 'number',
            message: '紧急程度必须为数字值',
            transform: (value) => Number(value)
          }
        ],
        frepairuser: [],
        frecdate: [],
        fcfdate: [],
        fdddate: [],
        fwcdate: [],
        flkdate: [],
        fbjnum: [
          {
            type: 'number',
            message: '维修得分必须为数字值',
            transform: (value) => Number(value)
          }
        ],
        fbjnote: [],
        fupddate: [],
        foperator: [],
        fcheckdate: [],
        fcheckuser: [],
        fbillstate: [
          {
            type: 'number',
            message: '报修状态必须为数字值',
            transform: (value) => Number(value)
          }
        ]
      },
      rules1: {
        fline: [
          { required: true, message: '行号不能为空' },
          {
            type: 'number',
            message: '行号必须为数字值',
            transform: (value) => Number(value)
          }
        ],
        // fimage: [{ required: true, message: '照片不能为空' }],
        fmemo: []
      },
      rules2: {
        frepairuser: [
          { required: true, message: '维修人员不能为空' }
        ]
      },
      fbillstateOptions: [
        { value: 1, label: '已报修' },
        { value: 2, label: '已接单' }
      ],
      freporttypeOptions: [
        { value: 1, label: '合约内' },
        { value: 2, label: '合约外' }
      ]
    }
  },
  created() {
    this.alarmdate = [
      this.parserDate(moment(new Date().setDate(1)).format('YYYY-MM-DD')),
      new Date()
    ]
    this.getList()
    fsiteOptionsByLevel(3)
      .then((response) => {
        this.getListfsiteNo = response.data.data.list
      })
      .catch(() => {
        this.getListfsiteNo = []
      })

    // 紧急程度
    getListArea({ flag: 20 })
      .then((response) => {
        this.getListferrorlevel = response.data.data.list
      })
      .catch(() => {
        this.getListferrorlevel = []
      })

    if (this.$store.state.user.fsiteLevel == 3) {
      this.listQuery.fsiteNo = this.$store.state.user.fsiteNo
      // 地点
      getListArea({ flag: 10, arg1: this.$store.state.user.fsiteNo })
        .then((response) => {
          this.getListfpointNo = response.data.data.list
        })
        .catch(() => {
          this.getListfpointNo = []
        })
      // 人员弹出框
      getListArea({ flag: 13, arg1: this.$store.state.user.fsiteNo })
        .then((response) => {
          this.getListuser = response.data.data.list
        })
        .catch(() => {
          this.getListuser = []
        })
    } else {
      // 地点
      getListArea({ flag: 10 })
        .then((response) => {
          this.getListfpointNo = response.data.data.list
        })
        .catch(() => {
          this.getListfpointNo = []
        })
      // 人员弹出框
      getListArea({ flag: 13 })
        .then((response) => {
          this.getListuser = response.data.data.list
        })
        .catch(() => {
          this.getListuser = []
        })
    }
    // 工程师
    userlist({ flag: 8, arg1: 13 })
      .then(response => {
        this.username = response.data.data.list
      })
      .catch(() => {
        this.username = []
      })
  },
  methods: {
    handleRemove() {},
    parserDate(date) {
      var t = Date.parse(date)
      if (!isNaN(t)) {
        return new Date(Date.parse(date.replace(/-/g, '/')))
      }
    },

    // 维修人员改变
    frepairuserChange(e) {
      if (e) {
        this.dataForm.fbillstate = 2
        this.dataForm.frecdate = new Date()
      } else {
        this.dataForm.fbillstate = 1
        this.dataForm.frecdate = null
      }
    },

    // 地点改变
    changeFpointNo: function(e) {
      this.dataForm.fequipmentbarcode = null
      this.dataForm.fequipmenttag = null
      this.dataForm.feuipmentid = null
      this.dataForm.freportuser = ''
      if (e) {
        listRoom({ fpointNo: e })
          .then((response) => {
            this.dataForm.freportuser = response.data.data.list[0].fperson
          })
          .catch(() => {
            this.dataForm.freportuser = ''
          })
      }
    },

    // 紧急程度
    formatferrorlevel: function(row, column) {
      if (this.getListferrorlevel) {
        for (let i = 0; i < this.getListferrorlevel.length; i++) {
          if (row.ferrorlevel == this.getListferrorlevel[i].value) {
            return this.getListferrorlevel[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 存放地点
    formatfpointNo: function(row, column) {
      if (this.getListfpointNo) {
        for (let i = 0; i < this.getListfpointNo.length; i++) {
          if (row.fpointNo === this.getListfpointNo[i].value) {
            return this.getListfpointNo[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },

    formatfsiteNo: function(row, column) {
      if (this.getListfsiteNo) {
        for (let i = 0; i < this.getListfsiteNo.length; i++) {
          if (row.fsiteNo === this.getListfsiteNo[i].value) {
            return this.getListfsiteNo[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },

    changeFsiteNo(data) {
      this.listQuery.fpointNo = ''
      this.listQuery.freportuser = ''
      this.listQuery.frepairuser = ''
      this.getListfpointNoArea = []
      this.getListuserArea = []
      if (data) {
        // 存放地点
        getListArea({ flag: 10, arg1: data })
          .then((response) => {
            this.getListfpointNoArea = response.data.data.list
          })
          .catch(() => {
            this.getListfpointNoArea = []
          })

        // 人员弹出框
        getListArea({ flag: 13, arg1: data })
          .then((response) => {
            this.getListuserArea = response.data.data.list
          })
          .catch(() => {
            this.getListuserArea = []
          })
      }
    },

    changeFsiteNoAdd(data) {
      this.dataForm.fpointNo = ''
      this.dataForm.freportuser = ''
      this.dataForm.frepairuser = ''
      this.getListfpointNoAreaAdd = []
      this.getListuserAreaAdd = []
      this.dataForm.fequipmentbarcode = null
      this.dataForm.fequipmenttag = null
      this.dataForm.feuipmentid = null
      this.dataForm.frecdate = null
      this.dataForm.fbillstate = 1
      if (data) {
        // 存放地点
        getListArea({ flag: 10, arg1: data })
          .then((response) => {
            this.getListfpointNoAreaAdd = response.data.data.list
          })
          .catch(() => {
            this.getListfpointNoAreaAdd = []
          })

        // 人员弹出框
        getListArea({ flag: 13, arg1: data })
          .then((response) => {
            this.getListuserAreaAdd = response.data.data.list
          })
          .catch(() => {
            this.getListuserAreaAdd = []
          })
        // 维修人员
        listArea({ fsiteNo: data, fsiteLevel: 3 })
          .then((response) => {
            if (response.data.data.list[0].fengineer) {
              this.dataForm.frepairuser = response.data.data.list[0].fengineer
              this.dataForm.frecdate = new Date()
              this.dataForm.fbillstate = 2
            } else {
              this.dataForm.frepairuser = ''
              this.dataForm.fbillstate = 1
            }
          })
          .catch(() => {
            this.dataForm.frepairuser = ''
            this.dataForm.fbillstate = 1
          })
      }
    },

    // 搜索人员弹出框
    searchDialoguse(value) {
      this.userFlag = value
      if (value === 'add') {
        this.userDialogFsiteNo = this.dataForm.fsiteNo
      } else if (value === 'addre') {
        this.userDialogFsiteNo = this.dataForm.fsiteNo
      } else if (value === 'searchre') {
        this.userDialogFsiteNo = this.listQuery.fsiteNo
      } else {
        this.userDialogFsiteNo = this.listQuery.fsiteNo
      }
      this.searchVisibleuse = true
    },

    // 人员弹出框返回值
    userDialogValue(value) {
      if (this.userFlag === 'add') {
        this.dataForm.freportuser = value.user.id.toString()
      } else if (this.userFlag === 'addre') {
        this.dataForm.frepairuser = value.user.id.toString()
      } else if (this.userFlag === 'searchre') {
        this.listQuery.frepairuser = value.user.id.toString()
      } else {
        this.listQuery.freportuser = value.user.id.toString()
      }
    },

    // 搜索地点弹出框
    searchDialoglab(value) {
      this.labFlag = value
      if (value === 'add') {
        this.labDialogFsiteNo = this.dataForm.fsiteNo
      } else {
        this.labDialogFsiteNo = this.listQuery.fsiteNo
      }
      this.searchVisiblelab = true
    },

    // 地点弹出框返回值
    labDialogValue(value) {
      if (this.labFlag === 'add') {
        this.dataForm.fpointNo = value.lab.fpointNo
        this.dataForm.fequipmentbarcode = null
        this.dataForm.fequipmenttag = null
        this.dataForm.feuipmentid = null
      } else {
        this.listQuery.fpointNo = value.lab.fpointNo
      }
    },

    // 固定资产码弹出框
    searchDialogcode(value) {
      this.codeDialogFsiteNo = this.dataForm.fsiteNo
      this.codeDialogfpointNo = this.dataForm.fpointNo
      this.searchVisiblecode = true
    },

    // 固定资产码弹出框返回值
    codeDialogValue(value) {
      this.dataForm.fequipmentbarcode = value.info.fequipmentbarcode
      this.dataForm.feuipmentid = value.info.feuipmentid
      this.dataForm.fequipmenttag = value.info.fequipmenttag
    },

    // 维修人员
    formatfrepairuser: function(row, column) {
      if (this.username) {
        for (let i = 0; i < this.username.length; i++) {
          if (row.frepairuser == this.username[i].value) {
            return this.username[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },
    // 报修人员
    formatfreportuser: function(row, column) {
      if (this.getListuser) {
        for (let i = 0; i < this.getListuser.length; i++) {
          if (row.freportuser == this.getListuser[i].value) {
            return this.getListuser[i].label
          }
        }
        return ''
      } else {
        return ''
      }
    },

    datetimeFormat(row, column) {
      const date = row[column.property]
      if (date === undefined || date === null) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD')
    },
    formatDate: function(date) {
      if (typeof date === 'object') {
        var ym
        var y = date.getFullYear()
        var m = date.getMonth() + 1
        var d = date.getDate()
        if (m < 10) {
          m = '0' + m
        }
        if (d < 10) {
          d = '0' + d
        }
        ym = '' + y + m + d
        return ym
      } else {
        return date
      }
    },
    getList() {
      this.listQuery.ftakedateStart =
        this.alarmdate == null ? null : this.formatDate(this.alarmdate[0])
      this.listQuery.ftakedateEnd =
        this.alarmdate == null ? null : this.formatDate(this.alarmdate[1])
      this.listLoading = true
      if (this.listQuery.fbillno == '') {
        this.listQuery.fbillno = null
      }
      listrepairHead(this.listQuery)
        .then((response) => {
          const temp = []
          let i = 0
          response.data.data.list.filter((item) => {
            if (item.fbillstate === 1 || item.fbillstate === 2) {
              temp.push(item)
              i++
            }
          })
          this.list = temp
          this.total = i
          this.listLoading = false
        })
        .catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resetForm() {
      this.dataForm = {
        fsiteNo: undefined,
        freportuser: undefined,
        freportdate: undefined,
        fpointNo: undefined,
        fequipmentbarcode: undefined,
        fequipmenttag: undefined,
        feuipmentid: undefined,
        freporttype: undefined,
        ferrormemo: undefined,
        ferrorlevel: undefined,
        frepairuser: undefined,
        frecdate: undefined,
        fcfdate: undefined,
        fdddate: undefined,
        fwcdate: undefined,
        flkdate: undefined,
        fbjnum: undefined,
        fbjnote: undefined,
        fupddate: undefined,
        foperator: undefined,
        fcheckdate: undefined,
        fcheckuser: undefined,
        fbillstate: undefined,
        id: undefined,
        details: []
      }
    },
    handleCreate() {
      this.resetForm()
      getFbillno({ flag: 2004 })
        .then((response) => {
          if (response) {
            this.dataForm.fbillno = response.data.data
            this.dialogFormVisible = true
            this.$nextTick(() => {
              this.$refs['dataForm'].clearValidate()
            })
          }
        })
        .catch(() => {
          this.dataForm.fbillno = ''
        })

      if (this.$store.state.user.fsiteLevel == 3) {
        this.dataForm.fsiteNo = this.$store.state.user.fsiteNo
        // 维修人员
        listArea({ fsiteNo: this.$store.state.user.fsiteNo, fsiteLevel: 3 })
          .then((response) => {
            if (response.data.data.list[0].fengineer) {
              this.dataForm.frepairuser = response.data.data.list[0].fengineer
              this.dataForm.frecdate = new Date()
              this.dataForm.fbillstate = 2
            } else {
              this.dataForm.frepairuser = ''
              this.dataForm.frecdate = null
              this.dataForm.fbillstate = 1
            }
          })
          .catch(() => {
            this.dataForm.frepairuser = ''
            this.dataForm.frecdate = null
            this.dataForm.fbillstate = 1
          })
      } else {
        this.getListfpointNoAreaAdd = []
        this.getListuserAreaAdd = []
      }

      this.dataForm.freportdate = new Date()
      this.dataForm.ferrorlevel = Number(this.getListferrorlevel[0].value)
      this.dataForm.freporttype = this.freporttypeOptions[0].value
      this.dialogStatus = 'create'
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.dataForm.foperator = this.$store.state.user.id
          this.dataForm.fupddate = new Date()
          createrepairHead(this.dataForm)
            .then((response) => {
              this.list.unshift(response.data.data)
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '添加设备维修主表成功'
              })
            })
            .catch((response) => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    },
    audit(row) {
      this.dialogVisible = true
      this.dataForm2 = Object.assign({}, row)

      // 存放地点
      getListArea({ flag: 10, arg1: row.fsiteNo })
        .then((response) => {
          this.getListfpointNoAreaAdd = response.data.data.list
        })
        .catch(() => {
          this.getListfpointNoAreaAdd = []
        })

      // 人员弹出框
      getListArea({ flag: 13, arg1: row.fsiteNo })
        .then((response) => {
          this.getListuserAreaAdd = response.data.data.list
        })
        .catch(() => {
          this.getListuserAreaAdd = []
        })
      this.$nextTick(() => {
        this.$refs['dataForm2'].clearValidate()
      })
      for (var i = 0; i < this.username.length; i++) {
        if (row.frepairuser == this.username[i].value) {
          this.dataForm2.frepairuser = this.username[i].label
        }
      }
    },

    handleUpdate(row) {
      this.listTmp = row
      this.actionsTmp = []
      row.details.forEach((v) => {
        this.actionsTmp.push(v)
      })

      this.dataForm = Object.assign({}, row)
      if (this.$store.state.user.fsiteLevel != 3) {
        // 存放地点
        getListArea({ flag: 10, arg1: row.fsiteNo })
          .then((response) => {
            this.getListfpointNoAreaAdd = response.data.data.list
          })
          .catch(() => {
            this.getListfpointNoAreaAdd = []
          })

        // 人员弹出框
        getListArea({ flag: 13, arg1: row.fsiteNo })
          .then((response) => {
            this.getListuserAreaAdd = response.data.data.list
          })
          .catch(() => {
            this.getListuserAreaAdd = []
          })
      }
      for (var i = 0; i < this.username.length; i++) {
        if (row.frepairuser == this.username[i].value) {
          this.dataForm.frepairuser = this.username[i].label
        }
      }
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.dataForm.foperator = this.$store.state.user.id
          this.dataForm.fupddate = new Date()
          updaterepairHead(this.dataForm, this.$route.query.id)
            .then(() => {
              for (const v of this.list) {
                if (v.fbillno === this.dataForm.fbillno) {
                  const index = this.list.indexOf(v)
                  this.list.splice(index, 1, this.dataForm)
                  break
                }
              }
              this.dialogFormVisible = false
              this.$notify.success({
                title: '成功',
                message: '更新设备维修主表成功'
              })
            })
            .catch((response) => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    },
    handleDelete(row) {
      this.$confirm('是否要删除设备维修主表', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleterepairHead(row)
          .then((response) => {
            this.$notify.success({
              title: '成功',
              message: '删除设备维修主表成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          })
          .catch((response) => {
            this.$notify.error({
              title: '失败',
              message: response
            })
          })
      })
    },
    indexMethod(index) {
      index = index + 1
      return index
    },
    handleUpdate1() {
      this.handleRemove()
      this.dataForm1 = {}
      this.dialogStatus1 = 'create'
      this.dialogFormVisible1 = true
      this.$nextTick(() => {
        this.$refs['dataForm1'].clearValidate()
      })
    },

    handleDelete1(row) {
      const index = this.dataForm.details.indexOf(row)
      this.dataForm.details.splice(index, 1)
      // this.dataForm.details.pop(row)
    },

    addData() {
      this.$refs['dataForm1'].validate((valid) => {
        if (valid) {
          this.dialogFormVisible1 = false
          this.dataForm.details.push(this.dataForm1)
        }
      })
    },
    // 弹窗点击关闭前的回调
    handleClose() {
      this.heddon = false
      this.dialogFormVisible = false
      this.list.forEach((v) => {
        if (v.fbillno === this.dataForm.fbillno) {
          this.dataForm = this.listTmp
          this.dataForm.details = this.actionsTmp
          const index = this.list.indexOf(v)
          this.list.splice(index, 1, this.dataForm)
          return
        }
      })
    },
    cancel() {
      this.heddon = false
      this.dialogFormVisible = false
      this.list.forEach((v) => {
        if (v.fbillno === this.dataForm.fbillno) {
          this.dataForm = this.listTmp
          this.dataForm.details = this.actionsTmp
          const index = this.list.indexOf(v)
          this.list.splice(index, 1, this.dataForm)
          return
        }
      })
    },

    // 图片
    formdata2: function(fpointno) {
      // const formdata = new FormData()
      // formdata.append('fpointno', '123456')
      return { ftype: '6', fpointno: fpointno }
    },
    handleAvatarSuccess(res, file) {
      // this.dataForm.fimage = URL.createObjectURL(file.raw)
      this.dataForm.fimage = res.data
      const time = new Date().getTime()
      this.heddon = true
      this.dataForm.fimage = `${this.dataForm.fimage}?time=${time}`
      this.dataForm1.fimage = this.dataForm.fimage
    },

    beforeAvatarUpload(file) {
      // const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      // if (!isJPG) {
      //   this.$message.error('上传头像图片只能是 JPG 格式!')
      // }
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!')
      }
      return isLt2M // isJPG &&
    },
    //* 图片
    //     //派工
    adds() {
      var dataFormlist = {
        userid: this.dataForm2.frepairuser,
        fbillno: this.dataForm2.fbillno
      }
      this.dataForm2.frecdate = moment(this.dataForm2.frecdate).format('YYYYMM')
      this.dataForm2.freportdate = moment(this.dataForm2.freportdate).format('YYYYMM')
      this.dataForm2.fupddate = moment(this.dataForm2.fupddate).format('YYYYMM')
      this.$refs['dataForm2'].validate((valid) => {
        if (valid) {
          createDispatch(dataFormlist)
            .then(response => {
              for (const v of this.list) {
                if (v.fbillno === this.dataForm2.fbillno) {
                  const index = this.list.indexOf(v)
                  this.list.splice(index, 1, this.dataForm2)
                  break
                }
              }
              this.dialogVisible = false
              this.$notify.success({
                title: '成功',
                message: '派工成功'
              })
            })
            .catch(response  => {
              this.$notify.error({
                title: '失败',
                message: response
              })
            })
        }
      })
    }

  }

}
</script>
